import { type ChannelItem, fetchChannelAPI } from "@/api/list"
import { useEffect, useState } from "react"

function useTabs() {
  const [channels, setChannels] = useState<ChannelItem[]>([
    {
      id: 1,
      name: 'test',
    },
    {
      id: 2,
      name: 'news',
    },
    {
      id: 3,
      name: 'games',
    },
  ])

  useEffect(() => {
    const getChannels = async () => {
      try {
        const res = await fetchChannelAPI()
        setChannels(res.data.channels)
      } catch (error) {
        console.error('fetch channel error')
      }
    }
    getChannels()
  }, [])

  return { channels }
}

export default useTabs